﻿namespace VisualPhysics.Scene.Core

open VisualPhysics.Scene.Core.Operators

/// Represents constant acceleration.
type ConstantAcceleration private (a : MVector<cm / s ^ 2>, dummy : unit) =
    let ax, ay = car a
    
    /// <summary>Creates a new constant acceleration.</summary>
    /// <param name="A">Acceleration as MVector of cm / s ^ 2.</param>
    new (a) =
        ConstantAcceleration(a, ())
        
    interface AccelerationManager with
        /// <summary>Gets the acceleration at a given time.</summary>
        /// <param name="Time">The time.</param>
        /// <returns>The acceleration.</returns>
        member this.GetAcceleration time = a
        /// <summary>Gets the velocity at a given time.</summary>
        /// <param name="Time">The time.</param>
        /// <param name="InitialV">The initial velocity.</param>
        /// <returns>The velocity.</returns>
        member this.GetVelocity time initialV =
            let vx, vy = car initialV
            let dvx, dvy = ax * time, ay * time
            let _vx, _vy = vx + dvx, vy + dvy
            pol (_vx, _vy)
        /// <summary>Gets the position at a given time.</summary>
        /// <param name="Time">The time.</param>
        /// <param name="InitialV">The initial velocity.</param>
        /// <param name="InitialP">The initial position.</param>
        /// <returns>The position.</returns>
        member this.GetPosition time initialV initialP =
            let x, y = car initialP
            let vx, vy = car initialV
            let _x, _y = x + vx * time + ax / 2.0 * time * time, y + vy * time + ay / 2.0 * time * time
            pol (_x, _y)
    end